/*- coding = utf-8 -*-
@Time : 2022/9/25 17:27
@Author : CSDN 沉默小管
@File : useClass.ts
@web  : golangblog.blog.csdn.net
@Software: WebStorm
*/

// ui封装模型

import {ElLoading, ElMessage, ElMessageBox, ElNotification} from "element-plus";

type msgType = "success"|"warning"|"info"|"error"

type msgBoxOptionType = "success"|"warning"|"info"|"error"
interface msgBoxOptionInterface {
    confirmButtonText:string,
    cancelButtonText?:string,
    distinguishCancelAndClose?: boolean,
    type?:msgBoxOptionType,
    draggable?:boolean,
}

type noticeTypeInterface = "success" | "error" | "warning" | "info"

type msgBoxTypeInterface = "confirm" | "prompt" | "alert"

interface optionInterface{
    target?:object|string
    body?:boolean
    fullscreen?:boolean
    text:string
    background?:string
    spinner?:string
}

export default {
    /**
     * 消息提示
     */
    handleMsg(message:string,type?:msgType){
        if(!type){
            type = "success"
        }
        if(type=="success"){
            ElMessage.success(`${message}`)
        }else if(type=="warning"){
            ElMessage.warning(`${message}`)
        }else if(type=="info"){
            ElMessage.info(`${message}`)
        }else if(type=="error"){
            ElMessage.error(`${message}`)
        }
    },


    /**
     * 消息彈出框
     */
    handleMsgBox(message?:string,msgTitle?:string,msgBoxOption?:msgBoxOptionInterface,type?:msgBoxTypeInterface){
        if(!type){
            type = "confirm"
        }
        let data;
        switch (type){
            case "confirm":
                data = ElMessageBox.confirm(message,msgTitle,msgBoxOption);
                break;
            case "prompt":
                data = ElMessageBox.prompt(message,msgTitle,msgBoxOption);
                break;
            case "alert":
                data = ElMessageBox.alert(message,msgTitle,msgBoxOption);
                break;
        }
        return data
    },


    /**
     * 通知
     * @param message
     * @param noticeType
     */
    handleNotification(message:string,noticeType:noticeTypeInterface,title:string='',otherOptions?:any){
        if(noticeType=="success"){
            ElNotification({
                title,
                message,
                type: 'success',
                ...otherOptions
            })
        }else if(noticeType=="warning"){
            ElNotification({
                title,
                message,
                type: 'warning',
                ...otherOptions
            })
        }else if(noticeType=="info"){
            ElNotification({
                title,
                message,
                type: 'info',
                ...otherOptions
            })
        }else if(noticeType=="error"){
            ElNotification({
                title,
                message,
                type: 'error',
                ...otherOptions
            })
        }
    },
    handleNotificationClose(){
        return ElNotification.closeAll()
    },
    //加载
    handleLoading(options:optionInterface){
        return ElLoading.service({
            text:options.text,
            body:options.body,
            fullscreen:options.fullscreen,
            spinner:options.spinner,
            background:options.background??"rgba(0, 0, 0, 0.7)",
        })
    }
}